-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
std: rework uefi allocators #22818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
std: rework uefi allocators #22818
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this is the right size for a PR like this :)
Two high level concerns:
- All allocators, including platform-specific ones like
WasmAllocatorcurrently live instd.heap. If we're moving these around that should be where. - Why are we adding additional abstractions on top of the UEFI-provided allocator functions? In general that's a good thing if it improves ergonomics of those APIs from a Zig perspective, but in this case no one but the allocator implementation should touch those, and I feel in that case the extra layer is not justified.
Will do
I'm not 100% sure, this originally came from @truemedian. |
e0ab1e2 to
da5fad6
Compare
Which additional abstractions are you referring to?
|
7efc07c to
a9862db
Compare
The ones in |
|
Ah, thats because this came out of a branch where the goal was to make |
linusg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rebase this after #22820 and provide a compelling use case for the custom layer in boot_services.zig or remove it.
lib/std/heap/uefi_allocators.zig
Outdated
| /// Allocates memory in pages. | ||
| /// | ||
| /// This allocator is backed by `allocatePages` and is therefore only suitable for usage when Boot Services are available. | ||
| pub const PageAllocator = struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The namespacing here is awkward, this ought to be a file-as-struct (UefiPageAllocator.zig).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why file as a struct when there's multiple allocators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because std.heap.UefiPageAllocator is much nicer than std.heap.uefi_allocators.PageAllocator (which violates https://ziglang.org/documentation/master/#Avoid-Redundant-Names-in-Fully-Qualified-Namespaces). Why do you want both allocators in the same file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
std.heap.UefiPageAllocatoris much nicer thanstd.heap.uefi_allocators.PageAllocator
Wouldn't std.heap.uefi.Page/Pool be nicer?
Why do you want both allocators in the same file?
Just so there isn't 3 more files that could fit into 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't std.heap.uefi.Page/Pool be nicer?
Not really, a "page" and a "page allocator" are different things. Avoiding redundancy does not mean to leave out important bits of information until the name has a different meaning.
Just so there isn't 3 more files that could fit into 1.
That's not a good reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've managed to find the time and split the allocators into their own files.
Already been rebased.
I don't have one unless @truemedian does. I think it just makes the API easier to use and it's already there. Shouldn't need additional maintenance since UEFI's API doesn't really change in that section. I probably will just remove it. |
I see at least one reference to |
a9862db to
33af113
Compare
Fixed, strange that one didn't get caught when I tried compiling |
For the most part Zig follows YAGNI principles. |
linusg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parts of this will be superseded by #23441.
|
Great, I'll rebase once that lands. Though I'm still wondering about #22818 (comment). |
33af113 to
9611057
Compare
dotcarmen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this pr should now be unblocked as well since #23441 landed :)
| /// Deprecated; to be removed after 0.14.0 is tagged. | ||
| pub const GeneralPurposeAllocator = DebugAllocator; | ||
|
|
||
| pub const uefi = @import("heap/uefi_allocators.zig"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i prefer to keep these in std.os.uefi, any reason to move them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forget who mentioned it but someone here mentioned that this is what should be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was me, but I've changed my mind - the split into file-as-struct is nice but let's keep them in std.os.uefi for now.
|
|
||
| /// Allocates memory pages from the system. | ||
| allocatePages: *const fn (alloc_type: AllocateType, mem_type: MemoryType, pages: usize, memory: *[*]align(4096) u8) callconv(cc) Status, | ||
| _allocatePages: *const fn (alloc_type: AllocateType.Enum, mem_type: MemoryType, pages: usize, memory: PhysicalAddress) callconv(cc) Status, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh that's a good point that i didn't address in my pr: the memory returned is a physical address, which shouldn't be used directly as a pointer
once you rebase i think it might make sense to keep that change (as opposed to *[*]uefi.Page), with the caveat that it should be memory: *PhysicalAddress and to return that PhysicalAddress from allocatePages. idk though, that would imply changing eg convertPointer which could get hairy
alternatively it would be nice if there was std.builtin.AddressSpace.physical but that could come with a cascade of changes that aren't necessarily relevant here.
9611057 to
d5966c8
Compare
|
Rebased, I haven't adjusted much but hopefully I resolved the conflicts well. |
| pages: usize, | ||
| ) AllocatePagesError![]align(4096) Page { | ||
| var ptr: [*]align(4096) Page = switch (location) { | ||
| var ptr: PhysicalAddress = switch (location) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you also have to fix the return type of the function and the .success arm of the switch below
Split off from #22226 as suggested by @linusg. This reworks the allocators to be more friendly.